Beginning jQuery by Jack Franklin & Russ Ferguson
Author:Jack Franklin & Russ Ferguson
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
That link is within a div, and as a simplified example, suppose that when the link is clicked, you’d like the background of the div to change to blue, and then nothing more to happen. The first attempt at this would probably look like so:
$(function() {
$("a").on("click", function() {
$("div").css("background", "blue");
});
});
If you try that in your browser, you will see the div turn blue for a split second before you are taken to the Apress web site. So, while it is executing your code, it’s then immediately whisking the user off to another site, rendering your code useless.
On the event object, along with stopPropagation() , there’s also preventDefault(), and you can probably figure out what that one does. You use it just as you did with stopPropagation()—pass in an event object to the event handler and then call preventDefault() on that object:
$(function() {
$("a").on("click", function(event) {
event.preventDefault();
$("div").css("background", "blue");
});
});
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9941)
The Mikado Method by Ola Ellnestam Daniel Brolund(9807)
Dependency Injection in .NET by Mark Seemann(9365)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7805)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7585)
Svelte with Test-Driven Development by Daniel Irvine(7388)
Test-Driven Development with PHP 8 by Rainier Sarabia(7129)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6986)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6551)
Web Development with Django by Ben Shaw Saurabh Badhwar(6447)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6441)
React Application Architecture for Production by Alan Alickovic(6169)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5827)
Kotlin in Action by Dmitry Jemerov(5088)
Audition by Ryu Murakami(4606)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4571)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4422)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4333)
Solidity Programming Essentials by Ritesh Modi(4130)
